package com.pennywise.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.jdbc.datasource.DriverManagerDataSource;
import javax.sql.DataSource;
import java.io.File;

@Configuration
public class SQLiteConfig {
    
    private static final String BASE_DIR = System.getProperty("user.dir") + "/data";
    
    @Bean
    public DataSource dataSource() {
        String dbPath = BASE_DIR + "/db/pennywise.db";
        
        // 确保数据库目录存在
        File dbDir = new File(dbPath).getParentFile();
        if (!dbDir.exists()) {
            dbDir.mkdirs();
        }
        
        DriverManagerDataSource dataSource = new DriverManagerDataSource();
        dataSource.setDriverClassName("org.sqlite.JDBC");
        dataSource.setUrl("jdbc:sqlite:" + dbPath);
        return dataSource;
    }
} 